<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <div class="widget-head am-cf">
                    <div class="widget-title am-cf">{$title}</div>
                </div>
				<div class="widget-body am-fr">
                    <!-- 工具栏 -->
                    <div class="page_toolbar am-margin-bottom-xs am-fr">
                        <form class="toolbar-form" action="{:url('order/export_order')}" method="post">
                            <div class="am-u-sm-12">
                                <div class="am fr">
                                    <div class="am-form-group tpl-form-border-form am-fl">
                                        <input type="text" name="data[star]"
                                               class="am-form-field"
                                               value="" placeholder="请选择起始日期"
                                               data-am-datepicker required>
                                    </div>
                                    <div class="am-form-group tpl-form-border-form am-fl">
                                        <input type="text" name="data[end]"
                                               class="am-form-field"
                                               value="" placeholder="请选择截止日期"
                                               data-am-datepicker required>
                                    </div>
                                    <div class="am-form-group am-fl">
                                        <div class="am-btn-toolbar">
                                            <div class="am-btn-group am-btn-group-xs">
                                                <button class="am-btn am-btn-secondary am-radius" type="submit">
                                                    <span class="am-icon-download"></span> 订单导出
                                                </button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </form>
                        <form class="toolbar-form" action="{:url('order/all_list')}">
                            <div class="am-u-sm-12">
                                <div class="am-fr">
                                    <div class="am-form-group am-fl">
                                        <div class="am-input-group am-input-group-sm tpl-form-border-form">
                                            <input type="text" class="am-form-field" name="search"
                                                   placeholder="请输入订单号" value="{$search}">
                                            <div class="am-input-group-btn">
                                                <button class="am-btn am-btn-default am-icon-search" type="submit"></button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="order-list am-scrollable-horizontal am-u-sm-12 am-margin-top-xs">
                        <table width="100%" class="am-table am-table-hover tpl-table-black am-table-centered am-text-nowrap am-margin-bottom-xs">
                            <thead>
                            <tr>
                                <th class="goods-detail">商品信息</th>
                                <th width="100px">单价/数量</th>
                                <th>实付款</th>
                                <th>买家</th>
                                <th>交易状态</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            {if !$list->isEmpty()}
                                {foreach $list as $order}
                                <tr class="order-empty">
                                    <td colspan="6"></td>
                                </tr>
                                <tr>
                                    <td class="am-text-middle am-text-left" colspan="6">
										<span class="am-margin-right-lg"># {$order['order_mode']['text']} #</span>
										{if $order['order_mode']['value']==10 and $order['table_id'] > 0}
                                            <span class="am-margin-right-lg">餐桌：{$order['table']['table_name']|default="--"}</span>
                                            {if $order['people']>0}
                                            <span class="am-margin-right-lg">人数：{$order['people']}</span>
                                            {/if}
                                        {else /}
                                            <span class="am-margin-right-lg">取餐号：{$order['row_no']}</span>
                                        {/if}
                                        <span class="am-margin-right-lg">来源：{$order['source']['text']}</span>
                                        <span class="am-margin-right-lg">订单号：{$order['order_no']}</span>
                                        <span class="am-margin-right-lg">下单时间：{$order['create_time']}</span>
                                    </td>
                                </tr>
                                <?php $i = 0;?>
                                {foreach $order['goods'] as $goods}
                                <?php $i++;?>
                                    <tr>
                                        <td class="goods-detail am-text-middle">
                                            <div class="goods-image">
                                                <img src="{$goods['image']['url']}" alt="">
                                            </div>
                                            <div class="goods-info">
                                                <p class="goods-title">{$goods['goods_name']}</p>
                                                <p class="goods-spec am-link-muted">
                                                    {$goods['goods_attr']}
                                                </p>
                                            </div>
                                        </td>
                                        <td class="am-text-middle">
                                            <p>￥{$goods['goods_price']} × {$goods['total_num']}</p>
											{if $order['order_status']['value']==40}
                                            <p>退 × {$goods['refund_num']}</p>
											{/if}
                                        </td>
                                        {if $i === 1}
                                        <?php $goodsCount = count($order['goods']); ?>
                                            <td class="am-text-middle" rowspan="{$goodsCount}">
                                                <p>￥{$order['pay_price']}</p>
                                                {if $order['activity_price'] > 0}
                                                <p class="am-link-muted">(优惠额：-￥{$order['activity_price']})</p>
                                                {/if}
												{if $order['pack_price'] > 0}
													<p class="am-link-muted">(包装费：+￥{$order['pack_price']})</p>
												{/if}
												{if $order['delivery_price'] > 0}
													<p class="am-link-muted">(配送费：+￥{$order['delivery_price']})</p>
												{/if}
												{if $order['order_status']['value'] == 40}
													<p>退款：-￥{$order['refund_price']}</p>
												{/if}
                                            </td>
                                            <td class="am-text-middle" rowspan="{$goodsCount}">
                                                <p>{$order['user']['nickname']|default="--"}</p>
                                                <p class="am-link-muted">(用户id：{$order['user']['user_id']|default="--"})</p>
                                            </td>
                                            <td class="am-text-middle" rowspan="{$goodsCount}">
                                                <p>付款状态：
                                                    <span class="am-badge
                                                {$order['pay_status']['value'] == 20 ? 'am-badge-success' : ''}">
                                                        {$order['pay_status']['text']}
                                                    </span>
                                                </p>
                                                <p>接单状态：
                                                    <span class="am-badge
                                                {$order['shop_status']['value'] == 20 ? 'am-badge-success' : ''}">
                                                        {$order['shop_status']['text']}
                                                    </span>
                                                </p>
                                                <p>配送状态：
                                                    <span class="am-badge
                                                {$order['delivery_status']['value'] == 20 ? 'am-badge-warning' : ''}
                                                {$order['delivery_status']['value'] == 30 ? 'am-badge-success' : ''}">
                                                        {$order['delivery_status']['text']}
                                                    </span>
                                                </p>
                                                <p>收货状态：
                                                    <span class="am-badge
                                                {$order['receipt_status']['value'] == 20 ? 'am-badge-success' : ''}">
                                                        {$order['receipt_status']['text']}
                                                    </span>
                                                </p>
												<p>订单状态：
												{if $order['order_status']['value'] == 40}
												<span class="am-badge
												{$order['refund_status']['value'] == 20 ? 'am-badge-danger' : ''} 
												{$order['refund_status']['value'] != 20 ? 'am-badge-warning' : ''}">
												{$order['refund_status']['text']}
													</span>
												{else /}
												    <span class="am-badge
                                                {$order['order_status']['value'] == 10 ? 'am-badge-warning' : ''}
												{$order['order_status']['value'] == 20 ? 'am-badge-danger' : ''}
												{$order['order_status']['value'] == 30 ? 'am-badge-success' : ''}">
												{$order['order_status']['text']}
													</span>
												{/if}
                                                </p>
                                            </td>
                                            <td class="am-text-middle" rowspan="{$goodsCount}">
                                                <div class="tpl-table-black-operation">
                                                    {if $order['order_status']['value'] == 10 or ($order['order_status']['value'] == 40 and $order['refund_status']['value'] != 20)}
                                                    <a class="hema-prints tpl-table-black-operation"
                                                        href="javascript:;" 
                                                        data-id="{$order['order_id']}">
                                                        打印订单
                                                    </a>
                                                    {/if}
                                                    <a class="tpl-table-black-operation-green"
                                                       href="{:url('order/detail', ['id' => $order['order_id']])}">
                                                        订单详情
                                                    </a>
                                                    {if $order['delivery_status']['value'] == 10 AND $order['order_status']['value'] == 10}
                                                        <a class="hema-cancel tpl-table-black-operation-warning"
                                                           href="javascript:;"
                                                           data-id="{$order['order_id']}">
                                                            取消订单
                                                        </a>
                                                    {/if}
                                                    {if $order['shop_status']['value'] == 10 AND $order['order_status']['value'] == 10}
                                                        <a class="hema-shop tpl-table-black-operation-del"
                                                           href="javascript:;"
                                                           data-id="{$order['order_id']}">
                                                            确认接单
                                                        </a>
                                                    {/if}
                                                    {if $order['shop_status']['value'] == 20 AND $order['delivery_status']['value'] == 10 AND $order['order_mode']['value'] != 20 AND $order['order_status']['value'] == 10}
                                                        <a class="hema-delivery tpl-table-black-operation-del"
                                                           href="javascript:;"
                                                           data-id="{$order['order_id']}">
                                                            确认发货
                                                        </a>
                                                    {/if}
                                                    {if $order['shop_status']['value'] == 20 AND $order['delivery_status']['value'] == 10 AND $order['order_mode']['value'] == 20 AND $order['order_status']['value'] == 10}
                                                        <a class="hema-waimai tpl-table-black-operation-del"
                                                           href="javascript:;"
                                                           data-id="{$order['order_id']}">
                                                            外卖配送
                                                        </a>
                                                    {/if}
                                                    {if $order['order_mode']['value'] == 20 AND $order['delivery_status']['value'] == 20 AND $order['delivery']['delivery_status']['value'] == 10 AND $order['order_status']['value'] == 10}
                                                        <a class="hema-wm-cancel tpl-table-black-operation-warning"
                                                           href="javascript:;"
                                                           data-id="{$order['order_id']}">
                                                            取消配送</a>
                                                    {/if}
                                                    {if $order['order_mode']['value'] == 20 AND $order['delivery_status']['value'] == 20 AND $order['delivery']['delivery_status']['value'] == 30 AND $order['delivery']['company']['value'] == 'self' AND $order['order_status']['value'] == 10}
                                                        <a class="hema-wm-status40 tpl-table-black-operation-warning"
                                                           href="javascript:;"
                                                           data-id="{$order['order_id']}">
                                                            开始配送</a>
                                                    {/if}
                                                    {if $order['order_mode']['value'] == 20 AND $order['delivery_status']['value'] == 20 AND $order['delivery']['delivery_status']['value'] == 40 AND $order['delivery']['company']['value'] == 'self' AND $order['order_status']['value'] == 10}
                                                        <a class="hema-wm-status50 tpl-table-black-operation-warning"
                                                           href="javascript:;"
                                                           data-id="{$order['order_id']}">
                                                            配送完毕</a>
                                                    {/if}
                                                    {if $order['order_mode']['value'] != 20 AND $order['table_id'] == 0 AND $order['delivery_status']['value'] == 30 AND $order['receipt_status']['value'] == 10 AND $order['order_status']['value'] == 10}
                                                        <a class="hema-spk tpl-table-black-operation-warning"
                                                           href="javascript:;"
                                                           data-id="{$order['row_no']}">
                                                            叫号取餐</a>
                                                    {/if}
                                                    {if $order['shop_status']['value'] == 20 AND $order['pay_status']['value'] == 10 AND $order['order_status']['value'] == 10}
                                                        <a class="hema-collection tpl-table-black-operation-warning"
                                                           href="javascript:;"
                                                           data-id="{$order['order_id']}">
                                                            确认收款
                                                        </a>
                                                    {/if}
                                                    {if $order['pay_status']['value'] == 20 AND $order['delivery_status']['value'] == 30 AND $order['receipt_status']['value'] == 10 AND $order['order_status']['value'] == 10}
                                                        <a class="hema-receipt tpl-table-black-operation-del"
                                                           href="javascript:;"
                                                           data-id="{$order['order_id']}">
                                                            确认完成
                                                        </a>
                                                    {/if}
                                                    {if $order['refund_status']['value'] == 10 AND $order['order_status']['value'] == 40}
                                                        <a class="hema-refund tpl-table-black-operation-del"
                                                           href="javascript:;"
                                                           data-id="{$order['order_id']}">
                                                            确认退款
                                                        </a>
                                                    {/if}
                                                </div>
                                            </td>
                                        {/if}
                                    </tr>
                                {/foreach}
                            {/foreach}
                            {else /}
                                <tr>
                                    <td colspan="6" class="am-text-center">暂无记录</td>
                                </tr>
                            {/if}
                            </tbody>
                        </table>
                    </div>
                    <div class="am-u-lg-12 am-cf">
                        <div class="am-fr">{:$list->render()} </div>
                        <div class="am-fr pagination-total am-margin-right">
                            <div class="am-vertical-align-middle">总记录：{:$list->total()}</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="order/waimai" /}
<script>
    $(function () {
        $('.hema-prints').del('id', "{:url('order/prints')}",'确定要重新打印该订单');
        $('.hema-cancel').del('id', "{:url('order/cancel')}",'确定取消该订单');
        $('.hema-shop').del('id', "{:url('order/shop')}",'确定要接订单');
        $('.hema-collection').del('id', "{:url('order/collection')}",'确认用户已付款');
        $('.hema-delivery').del('id', "{:url('order/delivery')}",'确认要发货');
        $('.hema-receipt').del('id', "{:url('order/receipt')}",'确认要完成订单');
        $('.hema-refund').confirms('id', "{:url('order/refund')}",'是否同意退款申请');
        $('.hema-wm-status40').del('id', "{:url('order/setDeliveryStatus?status=40')}",'确认要开始配送');
        $('.hema-wm-status50').del('id', "{:url('order/setDeliveryStatus?status=50')}",'确认配送完毕');
        $('.hema-wm-cancel').del('id', "{:url('order/cancelDelivery')}",'确认要取消该订单的配送');
        $('.hema-spk').del('id', "{:url('order/spk')}",'确认要叫号取餐');
        //外卖配送
        $('.hema-waimai').on('click', function () {
            var data = $(this).data();
            $.get("{:url('order/waimai')}?id=" + data.id, function (result) {
				if(result.code == 0){
				    $.show_error(result.msg);
				    return false;
				}
				let model = {
				    company:result.data.company,
				    clerk:result.data.clerk,
				    de:'abc'
				};
				$.showAction({
                    title: '外卖配送', 
                    area: '750px', 
                    content: template('tpl-waimai', model), 
                    uCheck: true, 
                    success: function ($content) {
                        // 切换配送方式
                        $('input:radio[name="data[company]"]').change(function (e) {
                            var $is_clerk = $('.is-clerk');
                            if (e.currentTarget.value === 'self') {
                                $is_clerk.show();
                            } else {
                                $is_clerk.hide();
                            }
                        });
                        $('#my-form').formPost({
                            url: "{:url('order/waimai')}?id=" + data.id
                        });
                    }, 
                    btn2: function ($content) {
                        return true;
                    }
                });
            });
        });
    });
</script>